<template>
  <el-dialog title="申请详情" :visible.sync="visible" :close-on-click-modal="false" append-to-body>
    <el-form ref="main-form" status-icon :model="mainQuery" :rules="rules" label-width="120px" label-position="left" :inline="false" style="width: 70%">
      <el-form-item     label="商户号" size="mini" prop="">
        <span v-text="data.mchNo"></span>
      </el-form-item>

      <el-form-item     label="操作类型" size="mini" prop="">
        <span v-text="data.strType"></span>
      </el-form-item>
      <el-form-item     label="申请金额" size="mini" prop="">
        <span v-text="data.transAmount"></span>
      </el-form-item>
      <el-form-item     label="申请币种" size="mini" prop="">
        <span v-text="data.transCurrency"></span>
      </el-form-item>

      <el-form-item     label="目标金额" size="mini" prop="">
        <span v-text="data.targetAmount"></span>
      </el-form-item>
      <el-form-item     label="目标币种" size="mini" prop="">
        <span v-text="data.targetCurrency"></span>
      </el-form-item>
      <el-form-item     label="手续费" size="mini" prop="">
        <span v-text="data.transFee"></span> {{data.transCurrency}}
      </el-form-item>
      <el-form-item     label="状态" size="mini" prop="">
        <span v-text="startList[data.handleStatus]"></span>
      </el-form-item>
      <el-form-item     label="申请时间" size="mini" prop="">
        <span v-text="data.createTime"></span>
      </el-form-item>
      <el-form-item label="提现信息">
      </el-form-item>
      <template v-if="data.type == 2 && data.extraType == 2">
        <el-form-item     label="平台邮箱账户:" size="mini" prop="">
          <span v-text="data.targetMchEmail"></span>
        </el-form-item>
      </template>
      <template v-else>
        <el-form-item     label="开户行名称" size="mini" prop="">
          <span v-text="data.bankAccountName"></span>
        </el-form-item>
        <el-form-item     label="开户行账号" size="mini" prop="">
          <span v-text="data.bankOpenBankNo"></span>
        </el-form-item>
        <el-form-item     label="开户行行号" size="mini" prop="">
          <span v-text="data.bankAccountNo"></span>
        </el-form-item>
      </template>

      <el-form-item label="提现方式">
      </el-form-item>
      <el-form-item    v-if="!data.targetMchEmail"  :label="'是否通过api'+data.strType" size="mini" prop=""  >
        <el-radio-group v-model="mainQuery.useApi"  :disabled="data.handleStatus ==1">
          <el-radio :label="true">是</el-radio>
          <el-radio :label="false">否</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item v-if="mainQuery.useApi" label="通道" size="mini" prop="">
        <el-select v-model="mainQuery.channelId" placeholder="选择通道" clearable  :disabled="data.handleStatus ==1">
          <el-option v-for="item in chaninOptions" :key="item.value" :label="item.label" :value="item.value">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="审核意见" size="mini" prop="remark">
        <el-input placeholder="" type="textarea" v-model="mainQuery.remark" clearable></el-input>
      </el-form-item>
    </el-form>

    <div slot="footer" class="dialog-footer">
      <!-- <el-popover
          v-if="id != null"
          placement="top"
          width="160"
          v-model="popDeleteVisible">
          <p>确定删除吗？</p>
          <div style="text-align: right; margin: 0">
            <el-button size="mini" type="default" @click="popDeleteVisible = false">取消</el-button>
            <el-button type="danger" size="mini" @click="submitDel">确定</el-button>
          </div>
          <el-button type="danger" slot="reference"  size="small" style="float: left;" :loading="loading">删 除</el-button>
        </el-popover> -->

      <el-button @click="close" size="mini">取 消</el-button>

      <el-popover v-if="rejectVisible" placement="top" width="160" v-model="popRejectVisible">
        <p>确定驳回审核吗?</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="default" @click="popRejectVisible = false">取消</el-button>
          <el-button type="danger" size="mini" @click="submit(false)" :loading="loading">驳回</el-button>
        </div>
        <el-button slot="reference" size="mini" type="danger" :loading="loading" style="float: left">驳回审核</el-button>
      </el-popover>

      <el-popover  placement="top" width="160" v-model="popConfirmVisible">
        <p>确定通过审核吗?</p>
        <div style="text-align: right; margin: 0">
          <el-button size="mini" type="default" @click="popConfirmVisible = false">取消</el-button>
          <el-button type="primary" size="mini" @click="submit(true)" :loading="loading">通过</el-button>
        </div>
        <el-button slot="reference" size="mini" type="primary" :loading="loading" style="margin-left: 10px">通过审核</el-button>
      </el-popover>
    </div>
  </el-dialog>
</template>

<script>

import ApiMain from '@/api/tradeTrans.list';

export default {
  mixins: [
  ],
  props: [
  ],
  data() {
    return {
      channelId:"",
      mainQuery: {
        useApi: false,
        channelId: '',
        isApprove: "",
        remark: "",
      },
      visible: false,
      rejectVisible: false,
      currentRemarkVisible: false,
      popConfirmVisible: false,
      popRejectVisible: false,
      chaninOptions: [],
      // 0.初审待审 1.初审通过 2.初审驳回 3.复审通过 4.复审驳回
      startList: {
        0: '初审待审',
        1: "初审通过",
        2: "初审驳回",
        4: "复审通过",
        4: "复审驳回"
      },
      loading: false,
      rules: {
        remark: [
          { required: true, message: '请填写内容', trigger: 'blur' },
        ],
      },

      id: null,
      data: {},

      action: '',
      strType: '',
      currentRemark: '',

    }
  },
  mounted() {
    this.mainQueryRaw = Object.copy(this.mainQuery);
  },

  methods: {

    async show(data, action) {
      this.reset();
      this.data = data;

      this.action = action;
      this.rejectVisible = true;
      this.currentRemarkVisible = true;

      switch (action) {
        case 'check':
          this.strType = action;
          this.currentRemark = this.data.createRemark;
          break;
        case 'recheck':
          this.strType = action;
          this.currentRemark = this.data.checkRemark;
          break;
      }
      this.chaninOptions = await ApiMain.getOptions({ canTransfer: 1 })
      console.log('弹窗详情', this.data)
      console.log('通道', this.chaninOptions)
      this.visible = true;
    },

    close() {
      this.visible = false;
      this.$emit('dialog-close');
    },

    reset() {
      this.$refs['main-form'] && this.$refs['main-form'].resetFields();
      this.id = null;
      this.data = null;
    },

    verifyForm() {
      var bool = true;
      this.$refs['main-form'].validate((valid) => bool = valid);
      return bool;
    },

    async submit(isConfirm) {
      this.popConfirmVisible = false;
      this.popRejectVisible = false;
      var req = Object.copy(this.mainQuery);
      req.id = this.data.id;
      req.isApprove = isConfirm;
      this.loading = true;
      var re = null;

      console.log(this.channelId)

      // 先判断 转账还是提现
      try {

        if (this.data.type == 2) {
          // 转账 
          if (this.strType == 'check') {
            // 初审
            let res = await ApiMain.transferFirstReview(req)

          } else {
            let res = await ApiMain.transferSecondReview(req)
          }
        } else {
          if (this.strType == 'check') {
            // 初审
            let res = await ApiMain.withdrawFirstReview(req)

          } else {
            let res = await ApiMain.withdrawSecondReview(req)
          }

        }
      } catch (err) { console.error(err) }
      this.$message({ message: '操作成功', type: 'success' });
      this.loading = false;

      this.close();
    },

  }
}
</script>

<style>
</style>
